package licode.unisop.log.service.infrastructure.repository.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import licode.unisop.unilite.dp.PageData;

import java.util.List;
import java.util.function.Function;

/**
 * 分页转换基类
 *
 * @author WR
 * @since 2016/7/9 16:31
 */
public class ServiceBase<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {
    public <K> PageData<K> convertPage(IPage<T> page, Function<List<T>, List<K>> call) {
        PageData<K> pageData = new PageData<>();
        if (page != null) {
            pageData.setCurrent(page.getCurrent());
            pageData.setSize(page.getSize());
            pageData.setTotal(page.getTotal());
            pageData.setData(call.apply(page.getRecords()));
        }
        return pageData;
    }
}